package com.itheima.health.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.itheima.health.dao.MemberDao;
import com.itheima.health.dao.OrderDao;
import com.itheima.health.service.ReportService;
import com.itheima.health.utils.DateUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.*;

/**
 * @author ：seanyang
 * @date ：Created in 2019/7/27
 * @description ：报表业务实现类
 * @version: 1.0
 */
@Service
@Slf4j
public class ReportServiceImpl implements ReportService {

	@Autowired
	private OrderDao orderDao;

	@Autowired
	private MemberDao memberDao;

	@Override
	public List<Map<String, Object>> findSetmealCount() {

		return orderDao.findSetmealCount();
	}

	@Override
	public Map<String, Object> findBusinessData() {
		Map<String, Object> reportData = new HashMap<>();
		// 初始化日期对象，今天、周一、月初
		Date today = DateUtils.getToday();
		Date weekMonday = DateUtils.getThisWeekMonday();
		Date firstDayInMonth=DateUtils.getFirstDay4ThisMonth();
		String strWeekday = "";
		String strMonthDay = "";
		String strDate = "";
		try{
		    strDate = DateUtils.parseDate2String(today);
			strWeekday = DateUtils.parseDate2String(weekMonday);
			strMonthDay= DateUtils.parseDate2String(firstDayInMonth);
		}catch(Exception e){
		    e.printStackTrace();
		}
		// 报表日期
		reportData.put("reportDate",strDate);
		// 会员相关
		reportData.put("todayNewMember",memberDao.totalMemberCountByDate(today));
		reportData.put("totalMember",memberDao.totalMemberCount());
		reportData.put("thisWeekNewMember",memberDao.totalMemberCountByAfterDate(weekMonday));
		reportData.put("thisMonthNewMember",memberDao.totalMemberCountByAfterDate(firstDayInMonth));
		// 预约相关
		reportData.put("todayOrderNumber",orderDao.findOrderCountByDate(today));
		reportData.put("thisWeekOrderNumber",orderDao.findOrderCountByAfterDate(weekMonday));
		reportData.put("thisMonthOrderNumber",orderDao.findOrderCountByAfterDate(firstDayInMonth));
		// 到诊相关
		reportData.put("todayVisitsNumber",orderDao.findVisitCountByDate(strDate));
		reportData.put("thisWeekVisitsNumber",orderDao.findVisitCountByAfterDate(strWeekday));
		reportData.put("thisMonthVisitsNumber",orderDao.findVisitCountByAfterDate(strMonthDay));
		//log.debug(">>>>:{},{}",orderDao.findVisitCountByAfterDate(weekMonday),orderDao.findVisitCountByAfterDate(firstDayInMonth));
		// 热门套餐
		reportData.put("hotSetmeal",orderDao.findHotsetmeal());

		return reportData;
	}

 @Override
 public List<Map<String, Object>> findSetmealCountSex() {
  return orderDao.findSetmealCountSex();
 }
}
